﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Web.Mvc
{
    /// <summary>
    /// Controller扩展
    /// </summary>
    public static class ControllerExtensions
    {
        /// <summary>
        /// 返回包含错误信息的json对象
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        public static JsonResult Error(this Controller controller, string errorMessage)
        {
            return new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { error = errorMessage } };
        }
    }
}
